﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Common
{
    public static class EnumEx
    {
        public static Boolean TryParse<TEnum>(String str, ref TEnum val)
        {
            return TryParse(str, ref val, false);
        }

        public static Boolean TryParse<TEnum>(String str, ref TEnum val, Boolean ignoreCase)
        {
            if (!String.IsNullOrEmpty(str))
            {
                try
                {
                    val = (TEnum)Enum.Parse(typeof(TEnum), str, ignoreCase);
                    return true;
                }
                catch
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }
    }
}
